﻿using AutoMapper;
using Comm100.Application.Services;
using Comm100.Framework.Auditing;
using Comm100.Framework.Authorization;
using Comm100.Public.Audit;
using Bot.Application.Dto;
using Bot.Application.Services;
using Bot.Domain.Bo;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using Bot.Domain;

namespace Bot.Application.AnswerInChannelPrompts.Service
{
    public class AnswerInChannelPromptAppService : BaseAppService, IAnswerInChannelPromptAppService
    {
        private IAnswerInChannelPromptDomainService _domainService;

        public AnswerInChannelPromptAppService(IAnswerInChannelPromptDomainService domainService) : base()
        {
            this._domainService = domainService;
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.ANSWERINCHANNELPROMPT, AuditAction.DESTROY)]
        public void Delete(Guid id)
        {
            _domainService.Delete(id);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.ANSWERINCHANNELPROMPT, AuditAction.CREATE)]
        public AnswerInChannelPromptDto Add(Guid answerInChannelId, AnswerInChannelPromptCreateDto dto)
        {
            AnswerInChannelPrompt answerInChannelPrompt = _domainService.CreateWithAnswerInChannelId(answerInChannelId, Mapper.Map<AnswerInChannelPrompt>(dto));
            return Mapper.Map<AnswerInChannelPromptDto>(answerInChannelPrompt);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.ANSWERINCHANNELPROMPT, AuditAction.UPDATE)]
        public AnswerInChannelPromptDto Update(Guid id, AnswerInChannelPromptUpdateDto dto)
        {
            AnswerInChannelPrompt answerInChannelPrompt = _domainService.Update(Mapper.Map<AnswerInChannelPromptUpdateBo>(dto));
            answerInChannelPrompt.Id = id;
            return Mapper.Map<AnswerInChannelPromptDto>(answerInChannelPrompt);
        }

        public AnswerInChannelPromptDto Get(Guid id, string include = "")
        {
            AnswerInChannelPrompt answerInChannelPrompt = _domainService.Get(id, include);
            return Mapper.Map<AnswerInChannelPromptDto>(answerInChannelPrompt);
        }

        public IEnumerable<AnswerInChannelPromptDto> GetList(Guid answerInChannelId, string include= "")
        {
            IEnumerable<AnswerInChannelPrompt> list = _domainService.GetByAnswerInChannelId(answerInChannelId, include);
            return Mapper.Map<IEnumerable<AnswerInChannelPromptDto>>(list);
        }
    }
}
